import Vue from "vue";
import {Toast} from "vant";

Vue.use(Toast);

class ToastMsg {
    loading(message = "加载中...", forbidClick = true, loadingType = "", duration = 0) {
        Toast.loading({
            message: message,
            forbidClick: forbidClick,
            loadingType: loadingType,
            duration: duration
        });
    }

    success(message = "",closeToast=null, icon = "success",duration=2000) {
        // Toast.success(content);
        Toast({
            message: message,
            icon: icon,
            duration:duration,
            onOpened: function () {
                if(closeToast){
                    setTimeout(function(){
                        closeToast()
                    },2000)
                }
            }
        });
    }


    fail(message = "") {
        Toast.fail(message);
    }

    clear() {
        Toast.clear();
    }

    err(message = "", position = "middle") {
        Toast({
            message: message,
            position: position,
        });
    }
}

let toast = new ToastMsg();
export default toast;
